package dinner.web.eat;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;

import dinner.web.ReportLine;

public class Report extends AbstractList<ReportLine> implements List<ReportLine> {

	private List<ReportLine> list = new ArrayList<ReportLine>();

	public void add(int index, ReportLine element) {
		ReportLine line = null;
		for (ReportLine i : list) {
			if (i.getName().equals(element.getName())) {
				line = i;
				break;
			}
		}
		if (line == null) {
			list.add(element);
		} else {
			line.getUserList().addAll(element.getUserList());
			line.setCount(line.getCount() + element.getCount());
		}
	}

	@Override
	public ReportLine get(int index) {
		return list.get(index);
	}

	public ReportLine remove(int index) {
		return list.remove(index);
	}

	public ReportLine set(int index, ReportLine element) {
		return list.set(index, element);
	}

	@Override
	public int size() {
		return list.size();
	}

}
